package com.lv.suyiyong.hfr.adapter

import android.graphics.Color
import com.chad.library.adapter.base.BaseQuickAdapter
import com.lv.common.base.DataBindBaseViewHolder
import com.lv.common.imp.OnPositionTListener
import com.lv.service.bean.BrandAttachedBean
import com.lv.suyiyong.hfr.R
import com.lv.suyiyong.hfr.databinding.ItemHotSalerTabBinding


/**
 * 作者： ygx
 * 创建日期：2022/6/24 8:10 PM
 * 签名： 天行健，君子以自强不息；地势坤，君子以厚德载物。
 *      _              _           _     _   ____  _             _ _
 *     / \   _ __   __| |_ __ ___ (_) __| | / ___|| |_ _   _  __| (_) ___
 *    / _ \ | '_ \ / _` | '__/ _ \| |/ _` | \___ \| __| | | |/ _` | |/ _ \
 *   / ___ \| | | | (_| | | | (_) | | (_| |  ___) | |_| |_| | (_| | | (_) |
 *  /_/   \_\_| |_|\__,_|_|  \___/|_|\__,_| |____/ \__|\__,_|\__,_|_|\___/
 *
 * You never know what you can do until you try !
 * ----------------------------------------------------------------
 *
 */
class HotSalerTabAdapter(private val datas: MutableList<BrandAttachedBean>?) :
    BaseQuickAdapter<BrandAttachedBean, DataBindBaseViewHolder>(
        R.layout.item_hot_saler_tab, datas
    ) {
    override fun convert(
        holder: DataBindBaseViewHolder,
        item: BrandAttachedBean,
        payloads: List<Any>
    ) {
        super.convert(holder, item, payloads)
        val mBinding: ItemHotSalerTabBinding =
            holder.getBind() as ItemHotSalerTabBinding
        if (item.selected == true) {
            mBinding.tvName.setTextColor(Color.parseColor("#ffffff"))
            mBinding.tvName.setBackgroundResource(com.lv.common.R.drawable.bg_fe9400_180801_12)
            mBinding.tvName.paint.isFakeBoldText = true
        } else {
            mBinding.tvName.setBackgroundResource(0)
            mBinding.tvName.setTextColor(Color.parseColor("#242424"))
            mBinding.tvName.paint.isFakeBoldText = false

        }
    }

    override fun convert(holder: DataBindBaseViewHolder, item: BrandAttachedBean) {
        val mBinding: ItemHotSalerTabBinding =
            holder.getBind() as ItemHotSalerTabBinding
//        mBinding.itemRoot = item
//        //防止列表闪烁
        mBinding.executePendingBindings()
        val layoutPosition = holder.layoutPosition
        mBinding.tvName.text = item.name
        if (item.selected == true) {
            mBinding.tvName.setTextColor(Color.parseColor("#ffffff"))
            mBinding.tvName.setBackgroundResource(com.lv.common.R.drawable.bg_fe9400_180801_12)
            mBinding.tvName.paint.isFakeBoldText = true
        } else {
            mBinding.tvName.setBackgroundResource(0)
            mBinding.tvName.setTextColor(Color.parseColor("#242424"))
            mBinding.tvName.paint.isFakeBoldText = false

        }
        mBinding.tvName.setOnClickListener {
            onViewItemClickListener?.onClick(layoutPosition, item)
        }
//        val layoutParams = clParent.layoutParams as RecyclerView.LayoutParams
//        if (layoutPosition == 0) {
//            layoutParams.topMargin = SizeUtils.dp2px(14.0f)
//        } else {
//            layoutParams.topMargin = SizeUtils.dp2px(12.0f)
//        }
//        clParent.layoutParams = layoutParams
//        clParent.setOnClickListener { onViewItemClickListener?.onClick(layoutPosition, item) }

    }

    var onViewItemClickListener: OnPositionTListener<BrandAttachedBean>? = null


}